$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'ratesdk'
require 'rubygems/user_interaction'
require 'pp'
require 'rainbow'
require 'launchy'
require 'ratecli/create'
require 'ratecli/delete'
require 'ratecli/index'
require 'ratecli/show'
require 'ratecli/helper'
require 'ratecli/run'
require 'rainbow/ext/string'

$sui = Gem::StreamUI.new($stdin, $stdout)

class RateCLI
  include RateCLI::Helper
  include RateCLI::Create
  include RateCLI::Delete
  include RateCLI::Index
  include RateCLI::Show
  include RateCLI::Run

  def initialize(client, per_page = 20)
    @client = client
    @sui = Gem::StreamUI.new($stdin, $stdout)
    @per_page = per_page
  end

  def others
    todo = choose_list("What to do?", %w{Register Status})
    if todo == 'Register'
      create('user')
    elsif todo == 'Status'
      result = @client.issue('status')
      puts hash2table(result)
    end
  end

  def main
    entity = choose_list("Play with?", %w{Views Benchmarks Algorithms Tasks Others})
    entity = entity.downcase[0..-2]

    if entity == 'other'
      others
    else
      index(entity)
    end
  end
end